package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.ZykUserSercetKeyDO;
import com.jinzhi.jzweb.service.ZykUserSercetKeyService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 用户与秘钥对应关系表
 * </pre>
 * <small> 2023-12-26 11:35:37 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/zykUserSercetKey")
public class ZykUserSercetKeyController extends BaseController {
	@Autowired
	private ZykUserSercetKeyService zykUserSercetKeyService;

	@Autowired
	private UserService userService;
	
	@GetMapping()
	String ZykUserSercetKey(){
	    return "jzweb/zykUserSercetKey/zykUserSercetKey";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public Result<Page<ZykUserSercetKeyDO>> list(String secreKeyId){
		EntityWrapper<ZykUserSercetKeyDO> selWrapper =new EntityWrapper();
		selWrapper.eq("secret_key_id",secreKeyId);
		selWrapper.orderBy("creater_date",false);
		// 查询列表数据
		Page<ZykUserSercetKeyDO> page = zykUserSercetKeyService.selectPage(getPage(ZykUserSercetKeyDO.class), selWrapper);
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			ZykUserSercetKeyDO obj = (ZykUserSercetKeyDO) page.getRecords().get(i);
			UserDO userDO = userService.selectById(obj.getUserId());
			obj.setUserMobile(userDO.getMobile());
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	

	
	@Log("删除用户与秘钥对应关系表")
	@PostMapping( "/remove")
	@ResponseBody
	public Result<String>  remove( Long id){

		zykUserSercetKeyService.deleteById(id);
        return Result.ok();
	}
	
}
